from functools import wraps

from flask import g, redirect, url_for
# 函数的装饰器
# 登录验证
def login_required(func):
    # 保留func的信息
    @wraps(func)
    # func(a, b, c) 
    def inner(*args, **kwargs):
        if g.user:
            return func(*args, **kwargs)
        else:
            return redirect(url_for("auth.login"))
    return inner

# @login_required
# def public_question(question_id):
#     pass
# 相当于===    login_required(public_question)(question_id)